/**
 * Project Name:spring-config-client File Name:StopEndpoint.java Package Name:org.spring.config.client.controller
 * Date:2019年10月16日下午7:16:24 Copyright (c) 2019, dengqian37@126.com All Rights Reserved.
 *
 */

package org.spring.cloud.pilot.endpoint.mvc;

import java.util.Collections;

import org.spring.cloud.pilot.endpoint.StopEndpoint;
import org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * ClassName:StopEndpoint <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason: TODO ADD REASON. <br/>
 * Date: 2019年10月16日 下午7:16:24 <br/>
 * 
 * @author dengqian
 * @version
 * @since JDK 1.8
 * @see
 */
/**
 * 服务暂停 ClassName: StopEndpoint <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason: TODO ADD REASON(可选). <br/>
 * date: 2019年10月16日 下午7:16:30 <br/>
 *
 * @author admin
 * @version
 * @since JDK 1.8
 */
public class StopMvcEndpoint extends EndpointMvcAdapter {

    public StopMvcEndpoint(StopEndpoint delegate) {

        super(delegate);

    }

    @RequestMapping(method = RequestMethod.POST)
    @ResponseBody
    @Override
    public Object invoke() {
        if (!getDelegate().isEnabled()) {
            return new ResponseEntity<>(Collections.singletonMap("message", "This endpoint is disabled"),
                HttpStatus.NOT_FOUND);
        }

        StopMvcEndpoint.super.invoke();

        return Collections.singletonMap("message", "Restarting");
    }

}
